package com.activenetwork.util.grid.condition;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;



public class EnabledCondition implements Condition {

	private int column;
	
	public void setColumn(int column) {
		this.column = column;
	}
	public int getColumn() {
		return column;
	}
	/**
	 * Empty constructor
	 */
	public EnabledCondition(){
		this.column = -1;
	}

	/**
	 * 
	 * @param column
	 * @param enabledSign
	 *            : using xpath format such as: "img[@name='enabled']" or
	 *            "input[@checked='checked']"
	 */
	public EnabledCondition(int column) {
		this.column = column;
	}
	
	@Override
	public boolean matchs(WebElement row) {

		List<WebElement> signs = row.findElements(By.xpath("./td[" + column
				+ "]/*"));
		if (signs.size() == 0) {
			return false;
		} else {
			WebElement sign = signs.get(0);
			if (sign.getTagName().equals("img")
					&& sign.getAttribute("name").equals("enabled")) {
				return true;
			}
			if (sign.getTagName().equals("input") && sign.isSelected()) {
				return true;
			}
			if (sign.getTagName().equals("img")
					&& sign.getAttribute("src").contains("icon_check"))
				return true;
			return false;
		}
		// if (imgList.size() != 0 || checkboxList.size() != 0) {
		// return true;
		// }
		// return false;
	}

}
